﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Pattern_package
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Create_Correct_Pattern.SampleImage newSampleImage;
        private void BtnCreateImage_Click(object sender, EventArgs e)
        {
            numberOfClass = int.Parse(this.txtNumOfClass.Text);
            Create_Correct_Pattern.NormalDistrubution[] classInfo = new Create_Correct_Pattern.NormalDistrubution[numberOfClass];
            for (int i = 0; i < numberOfClass; i++)
            {
                classInfo[i].mean = double.Parse(this.dataGridView1.Rows[i].Cells[0].Value.ToString());
                classInfo[i].sigma = double.Parse(this.dataGridView1.Rows[i].Cells[1].Value.ToString());
            }
            newSampleImage = new Create_Correct_Pattern.SampleImage();
            this.PicPattarnCreated.Image = newSampleImage.CreateSampleImage(int.Parse(this.txtWidth.Text), int.Parse(this.txtHeight.Text), numberOfClass, classInfo);
        }

        private void BtnBeginClassify_Click(object sender, EventArgs e)
        {
            this.numberOfClass = int.Parse(this.txtNumOfClass.Text);
            GUI.Classify_Form newClassifyForm = new GUI.Classify_Form();
            newClassifyForm.SetValues(this.newSampleImage.valueOfPixelInImage, "S", this.numberOfClass, (Bitmap)this.PicPattarnCreated.Image);
            newClassifyForm.ShowDialog();
        }

        public int numberOfClass { get; set; }

        private void BtnOpen_Click(object sender, EventArgs e)
        {
            
            Bitmap image =new Bitmap(1,1);
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {

                string opendFileName = openFileDialog1.FileName;
                image = new Bitmap(opendFileName);
                this.PicPattarnCreated.Image = image;
            }

            newSampleImage = new Create_Correct_Pattern.SampleImage();
            newSampleImage.CalcvalueOfPixelInImage(image);
        }
    }
}
